package com.akk.module.avs.service;

import com.akk.module.avs.entity.AvsYbCardAccess;
import com.akk.module.avs.entity.AvsYbCardAccessExample;
import com.akk.module.avs.entity.AvsYbTags;
import com.akk.module.avs.entity.AvsYbTagsExample;
import com.akk.module.avs.mapper.AvsYbCardAccessMapper;
import com.akk.module.avs.mapper.AvsYbTagsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class AvsYbCardAccessService {

    @Autowired
    private AvsYbCardAccessMapper cardAccessMapper;

    @Autowired
    private AvsYbCardAccessExample cardAccessExample;

    public List<AvsYbCardAccess> findByParams(Map params){
        cardAccessExample.clear();
        AvsYbCardAccessExample.Criteria criteria = cardAccessExample.createCriteria();
        if (params.containsKey("appId"))
            criteria.andAppIdEqualTo(params.get("appId").toString());
        if (params.containsKey("status"))
            criteria.andStatusEqualTo(Integer.valueOf(params.get("status").toString()));
        if (params.containsKey("startDate") && params.containsKey("endDate"))
            criteria.andCreateDateGreaterThanOrEqualTo((Date) params.get("startDate")).andCreateDateLessThanOrEqualTo((Date) params.get("endDate"));
        return cardAccessMapper.selectByExample(cardAccessExample);
    }

    public AvsYbCardAccess findById(Long accessId){
        return cardAccessMapper.selectByPrimaryKey(accessId);
    }

    public void save(AvsYbCardAccess access){
        cardAccessMapper.insert(access);
    }

    public void update(AvsYbCardAccess access){
        cardAccessMapper.updateByPrimaryKey(access);
    }

    public void del(Long accessId){
        cardAccessMapper.selectByPrimaryKey(accessId);
    }



}
